package com.glorysoft.lipuxinpda.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.glorysoft.lipuxinpda.R;
import com.glorysoft.lipuxinpda.entity.KeyValueEntity;
import com.glorysoft.lipuxinpda.entity.ShowMaterialInReturnEntity;

import java.util.List;

public class MaterialExchangeScanAdapter extends RecyclerView.Adapter<MaterialExchangeScanAdapter.MaterialViewHolder>{

    private List<KeyValueEntity> data;

    public void setData(List<KeyValueEntity> data) {
        this.data = data;
    }

    @NonNull
    @Override
    public MaterialViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_textview, parent, false);
        return new MaterialViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MaterialViewHolder holder, int position) {
        holder.tv_key.setText(data.get(position).getID_CH());
        holder.tv_value.setText(data.get(position).getVALUE());
    }

    @Override
    public int getItemCount() {
        return Math.max(data.size(), 0);
    }

    class MaterialViewHolder extends RecyclerView.ViewHolder{

        private TextView tv_key;//字段名
        private TextView tv_value;//字段值

        public MaterialViewHolder(View itemView) {
            super(itemView);
            tv_key =  itemView.findViewById(R.id.tv_key);
            tv_value =  itemView.findViewById(R.id.tv_value);
        }
    }
}
